﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraCharts;
using Lib.Utils;

namespace MS.INV.Reports.Costs
{
    public partial class Costs_Chart_Year : Lib.Bases.Forms.BaseForm
    {
        DataTable DT_C = new DataTable();
        public Costs_Chart_Year()
        {
            InitializeComponent();

            nuYear.EditValue = DateTime.Now.Year;
        }

        private void btRef_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                pivot.DataSource = DBLayer.ExecDataTable("Rpt_CostsChartYear", "Command,Year", "Detail", Cvert.ToInt32(nuYear.EditValue, 0));

                DT_C = DBLayer.ExecDataTable("Rpt_CostsChartYear", "Command,Year", "Summary", Cvert.ToInt32(nuYear.EditValue, 0));
                chart.Series[0].DataSource = DT_C;
                chart.Series[0].ArgumentDataMember = "Thang";
                chart.Series[0].ValueScaleType = ScaleType.Numerical;
                chart.Series[0].ValueDataMembers.AddRange(new string[] { "TongTien" });
                chart.Series[0].LegendText = Cvert.ToInt32(nuYear.EditValue, 0).ToString();
            }
            catch (Exception ex)
            {
                Lib.Bases.SysError.RaiseError(ex, this.Name, "Load data");
            }
        }

        private void btExcel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            using (Exports.Costs.Costs_Chart_Year cls = new Exports.Costs.Costs_Chart_Year())
            {
                cls.DoExport(DT_C, Cvert.ToInt32(nuYear.EditValue, 0));
            }

            if (System.IO.File.Exists(Application.StartupPath + @"\Export Xls\Costs_Chart_Year.xls"))
                Lib.Utils.Uti.RunFile(Application.StartupPath + @"\Export Xls\Costs_Chart_Year.xls");
        }

        private void btClose_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.Close();
        }
    }
}
